package com.contract.commonlib.util.ext

import android.util.Log
import android.view.Gravity
import com.blankj.utilcode.util.ToastUtils
import com.blankj.utilcode.util.Utils
import com.contract.commonlib.BuildConfig

private var lastToastTime = 0L
private var lastToastContent = ""

/**
 * 自定义toast
 */
fun Any.showToast(msg: String?, isLong: Boolean = false) {
    if (msg.isNullOrBlank()) return
    if (lastToastContent == msg && System.currentTimeMillis() - lastToastTime < 2000) {
        return
    } else {
        lastToastTime = System.currentTimeMillis()
        lastToastContent = msg
    }
    ToastUtils.getDefaultMaker().setGravity(Gravity.CENTER,0,0)
    if (isLong){
        ToastUtils.showLong(msg)
    }else{
        ToastUtils.showShort(msg)
    }
}


fun Any.showToast(stringId: Int) {
    try {
        showToast(Utils.getApp().getString(stringId))
    } catch (e: Exception) {

    }
}

/**
 * 常规日志打印
 * 过滤关键字 logcom
 */
fun logcom(msg: String?) {
    if (BuildConfig.DEBUG && msg != null) Log.v("LogCom", msg)
}
fun logcom(tag :String,msg: String?) {
    if (BuildConfig.DEBUG && msg != null) Log.v(tag, msg)
}
/**
 * 流程日志打印
 * 过滤关键字 logprocess
 */
fun logprocess(msg: String?) {
    if (BuildConfig.DEBUG  && msg != null) Log.i("LogProcess", msg)

}